<template>
  <!--ASN明细-->
  <div id="AsnDetails">
    <g-details :detailData="data.detailData" :inputConfig="inputConfig" :rules="rules" @pop="setdata"></g-details>
  </div>
</template>

<script>
import baseMixin from '@/mixins/BaseMixin'

export default {
  name: 'AsnDetails',
  mixins: [baseMixin],
  props: {
    data: {
      type: Object
    }
  },
  data() {
    return {
      rules: {
        orderlinenumber: [{ required: true, trigger: 'blur' }],
        storerkey: [{ required: true, trigger: 'blur' }],
        sku: [{ required: true, trigger: 'blur' }],
        packkey: [{ required: true, trigger: 'blur' }],
        uom: [{ required: true, trigger: 'blur' }],
        status: [{ required: true, trigger: 'blur' }],
        openqty: [
          { required: true, trigger: 'blur' },
          { validator: this.verify, trigger: 'blur' }
        ],
        qtypreallocated: [{ validator: this.verify, trigger: 'blur' }],
        cartonbreak: [{ required: true, trigger: 'blur' }]
      }
    }
  },
  computed:{
    inputConfig(){
      return [
        {
          type: 'input',
          label: this.$t('outbound.userlinenumber'),
          disabled: true,
          props: 'orderlinenumber'
        },
        {
          type: 'select',
          label: this.$t('common.status'),
          disabled: true,
          props: 'status',
          options: this.getOptions('queryOrderStatusDropDown')
        },

        {
          type: 'table',
          label: this.$t('config.shipper'),
          disabled: true,
          // disabled: !this.$store.state.newFlag && !this.$store.state.detailsNew,
          props: 'storerkey',
          tableConfig: [
            {
              label: this.$t('config.shipper'),
              prop: 'storerkey',
              input: 'input'
            },
            {
              label: this.$t('config.company'),
              prop: 'company',
              input: 'input'
            },
            {
              label: this.$t('config.city'),
              prop: 'city',
              input: 'input'
            },
            {
              label: this.$t('config.provice'),
              prop: 'state',
              input: 'input'
            },
            {
              label: this.$t('config.postcode'),
              prop: 'zip',
              input: 'input'
            },
            {
              label: this.$t('config.contact'),
              prop: 'contact',
              input: 'input'
            },
            {
              label: this.$t('config.phone'),
              prop: 'phone',
              input: 'input'
            }
          ],
          url: `queryStorer/1/?/${this.$store.state.wms}`
        },
        {
          type: 'table',
          label: this.$t('config.sku'),
          disabled: !this.data.detailData.storerkey,
          props: 'sku',
          tableConfig: [
            {
              label: this.$t('config.sku'),
              prop: 'sku',
              input: 'input'
            },
            {
              label: this.$t('common.desc'),
              prop: 'descr',
              input: 'input'
            },
            {
              label: this.$t('config.shipper'),
              prop: 'storerkey',
              input: 'input'
            },
            {
              label: this.$t('config.packaging'),
              prop: 'packkey',
              input: 'input'
            },
            {
              label: this.$t('config.boxGroup'),
              prop: 'cartongroup',
              input: 'input'
              //options: this.getOptions("queryCartonizationDropDown")
            },
            {
              label: this.$t('config.allocaStrategy'),
              prop: 'strategykey',
              input: 'input'
              //options: this.getOptions("queryAllocatestrategyDropDown")
            },
            {
              label: this.$t('config.putawayStrategy'),
              prop: 'putawaystrategykey',
              input: 'input'
              //options: this.getOptions("queryPutawaystrategyDropDown")
            },
            {
              label: this.$t('config.batchValidate'),
              prop: 'lottablevalidationkey',
              input: 'input'
              //options: this.getOptions("queryLottablevalidationDropDown")
            },
            {
              label: this.$t('config.area'),
              prop: 'putawayzone',
              input: 'input'
              //options: this.getOptions("queryPutawayzoneDropDown")
            }
          ],
          filterKey: ['descr', 'sku'],
          filterUrl: `fuzzyQuerySkuByItemNumberAndName/undefined`,
          url: `querySkuOfStorerkey/?/${this.$store.state.wms}/undefined`
        },
        {
          type: 'input',
          label: this.$t('config.goodsDesc'),
          disabled: true,
          props: 'skudescr'
        },
        {
          type: 'select',
          label: this.$t('config.goodsPackage'),
          disabled: false,
          props: 'packkey',
          options: this.getOptions('queryPackDropDown')
        },
        {
          type: 'select',
          label: this.$t('config.measureUnit'),
          disabled: false,
          props: 'uom',
          options: [],
          break: true
        },
        {
          type: 'input',
          label: this.$t('in.surplusqty'),
          disabled: false,
          props: 'openqty'
        },
        {
          type: 'input',
          label: this.$t('out.originalqty'),
          disabled: true,
          props: 'originalqty'
        },
        {
          type: 'input',
          label: this.$t('out.qtypreallocated1'),
          disabled: true,
          props: 'qtypreallocated'
        },
        {
          type: 'input',
          label: this.$t('out.qtyallocated'),
          disabled: true,
          props: 'qtyallocated'
        },
        {
          type: 'input',
          label: this.$t('outbound.qtypicked'),
          disabled: true,
          props: 'qtypicked'
        },
        {
          type: 'input',
          label: this.$t('out.shippedqty'),
          disabled: true,
          props: 'shippedqty',
          break: true
        },
        {
          type: 'select',
          label: this.$t('in.qcrequired'),
          disabled: false,
          props: 'oqcrequired',
          options: this.getOptions('querycodeLkup/YESNO')
        },
        {
          type: 'select',
          label: this.$t('in.qcautoadjust'),
          disabled: false,
          props: 'oqcautoadjust',
          options: this.getOptions('querycodeLkup/YESNO')
        },
        {
          type: 'input',
          label: this.$t('out.cartonbreak'),
          disabled: true,
          props: 'cartonbreak'
        },
        {
          type: 'input',
          label: this.$t('out.cartonqtybreak'),
          disabled: false,
          props: 'cartonqtybreak'
        },
        {
          type: 'input',
          label: this.$t('out.stageloc'),
          disabled: false,
          props: 'stageloc'
        },
        {
          type: 'input',
          label: this.$t('out.externlineno'),
          disabled: true,
          props: 'externlineno'
        }
      ]
    }
  },
  methods: {
    verify(rule, value, callback) {
      if (value === '') {
        callback(new Error())
      } else {
        var re = /^[0-9]*$/
        let te = value
        let flag = re.test(te)
        if (flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
            this.inputData[rule.field] = 0
            callback(new Error())
          } else {
            callback()
          }
        } else {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
          this.inputData[rule.field] = 0
          callback(new Error())
        }
      }
    },
    setdata(data, close, listId) {
      if (listId == 'storerkey') {
        this.data.detailData.storerkey = data.storerkey
      } else if (listId == 'sku') {
        console.log(data)
        this.data.detailData.sku = data.sku
        this.data.detailData.packkey = data.packkey
        this.data.detailData.skudescr = data.descr
        this.data.detailData.newallocationstrategy = data.newallocationstrategy
        this.data.detailData.preallocatestrategykey =
          data.preallocatestrategykey
        this.data.detailData.allocatestrategykey = data.strategykey
      }
      close(false)
    }
  },
  mounted() {},
  watch: {
    '$parent.$parent.$refs.detail.detailData.storerkey': {
      handler(data) {
        this.data.detailData.storerkey = data
      },
      deep: true,
      immediate: true
    },
    'data.detailData.storerkey': {
      handler(data) {
        this.inputConfig.forEach(item => {
          if (item.props == 'sku') {
            item.filterUrl = 'fuzzyQuerySkuByItemNumberAndName/' + data
            item.url = 'querySkuOfStorerkey/?/wmwhse1/' + data
          }
        })
      },
      deep: true,
      immediate: true
    },
    'data.detailData.packkey': {
      handler(data) {
        this.inputConfig.forEach(item => {
          if (item.props == 'uom') {
            item.options = this.getOptions(`queryFfdefaultuomDropDown/${data}`)
          }
        })
      },
      deep: true,
      immediate: true
    }
  }
}
</script>

<style scoped></style>
